package com.xiao.collection;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author lao xiao
 * @date 2025-04-18 15:06
 */
public class TestSort {
    public static void main(String[] args) {
        Person1[] p1 = new Person1[]{new Person1(1),new Person1(2),new Person1(3)};
        Person2[] p2 = new Person2[]{new Person2(1),new Person2(2),new Person2(3)};
        Arrays.sort(p1);
        Arrays.sort(p2,new Person2());
    }

    @AllArgsConstructor
    static class Person1 implements Comparable<Person1> {
        public int age;
        @Override
        public int compareTo(Person1 o) {
            return age-o.age;
        }
    }

    @AllArgsConstructor
    @NoArgsConstructor
    static class Person2 implements Comparator<Person2> {
        public int age;
        @Override
        public int compare(Person2 o1, Person2 o2) {
            return o1.age-o2.age;
        }
    }
}
